package com.itsm.example.audit.pojo.event;

import com.itsm.example.statemachine.bo.ItsmEvent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author benym
 * @date 2023/7/12 15:57
 */
@Data
public class AuditEvent extends ItsmEvent {


    public static final AuditEvent NEW = new AuditEvent(0, "申请", "newForm");
    public static final AuditEvent PASS = new AuditEvent(1, "同意", "approveForm");
    public static final AuditEvent REJECT = new AuditEvent(2, "不同意", "rejectForm");
    public static final AuditEvent DONE = new AuditEvent(3, "结束", "closeForm");



    private static final Map<Integer, AuditEvent> CODE_MAP = new ConcurrentHashMap<>();

    static {
        CODE_MAP.put(0, new AuditEvent(0, "申请", "newForm"));
        CODE_MAP.put(1, new AuditEvent(1, "同意", "approveForm"));
        CODE_MAP.put(2, new AuditEvent(2, "不同意", "rejectForm"));
        CODE_MAP.put(3, new AuditEvent(3, "结束", "closeForm"));
    }

    public static AuditEvent getEvent(Integer code) {
        return CODE_MAP.get(code);
    }


    AuditEvent(Integer id, String desc,String jsForm) {

        super.setId(id);
        super.setName(desc);
        super.setJsForm(jsForm);
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ItsmEvent s = (ItsmEvent) o;
        return Objects.equals(getId(), s.getId());
    }
    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }

    @Override
    public String  toString() {
        return "AuditEvent{" +
                "id=" + getId() +
                ", desc='" + getName() + '\'' +
                ", jsForm='" + getJsForm() + '\'' +
                '}';
    }
}
